package com.elink.enginerring.video;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.common.BaseCo;
import com.elink.enginerring.common.Constant;
import com.elink.enginerring.common.ErrorType;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;
import com.elink.enginerring.user.entity.User;
import com.elink.enginerring.util.JSONUtil;
import com.elink.enginerring.video.entity.PlannHier;
import com.elink.enginerring.video.service.IPlannHierService;

@Controller
@RequestMapping("/view/plan")
@Api(value="规划体系接口")
public class PlannHierController {
	@Autowired
	private  IPlannHierService plannHierService;
	
	/**
	 * 分页获取规划体系
	 * @param co
	 * @return
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ApiOperation(value = "获取规划体系", httpMethod = "GET",  notes = "分页获取规划体系")
	@ResponseBody
	public Map<String, Object>getList(@ModelAttribute @Valid BaseCo co){
		DataSourceContextHolder.setDbType(DataSourceType.DBHIER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		return plannHierService.getList(co);
	}
	
	/**
	 * 添加规划体系
	 * @param ph
	 * @return
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ApiOperation(value = "添加规划体系", httpMethod = "POST",  notes = "添加规划体系")
	@ResponseBody
	public Map<String, Object>add(@ModelAttribute @Valid PlannHier ph,HttpSession session){
		DataSourceContextHolder.setDbType(DataSourceType.DBHIER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		User user = 	(User) session.getAttribute(Constant.su_in_session);
		ph.setCreateUserId(user.getUserId());
		return plannHierService.add(ph);
	}
	/**
	 * 修改规划体系
	 * @param ph
	 * @return
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	@ApiOperation(value = "修改规划体系", httpMethod = "POST",  notes = "修改规划体系")
	@ResponseBody
	public Map<String, Object>modify(@ModelAttribute @Valid PlannHier ph,HttpSession session){
		DataSourceContextHolder.setDbType(DataSourceType.DBHIER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		User user = 	(User) session.getAttribute(Constant.su_in_session);
		ph.setUpdateUserId(user.getUserId());
		return plannHierService.modify(ph);
	}
	
	/**
	 * 删除规划体系
	 * @param ph
	 * @return
	 */
	@RequestMapping(value = "/del", method = RequestMethod.GET)
	@ApiOperation(value = "删除规划体系", httpMethod = "GET",  notes = "删除规划体系")
	@ResponseBody
	public Map<String, Object>del(@RequestParam(value="ids",required=true)String ids){
		DataSourceContextHolder.setDbType(DataSourceType.DBHIER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType()); 
		 plannHierService.del(ids);
		 return JSONUtil.getJSON(ErrorType.SUCCESS);
	}
}
